﻿using System;
using System.Collections;

namespace Framework.Unity
{
    public class ExceptionDressingContainer : IContainer
    {
        private readonly IContainer _container;

        public ExceptionDressingContainer(IContainer container)
        {
            _container = container;
        }

        public object GetA(Type contract)
        {
            try
            {
                return _container.GetA(contract);
            }
            catch (Exception ex)
            {
                throw new ImplementationRetrievalException(contract, ex);
            }
        }

        public object GetA(Type contract, IDictionary parameters)
        {
            try
            {
                return _container.GetA(contract, parameters);
            }
            catch (Exception ex)
            {
                throw new ImplementationRetrievalException(contract, ex);
            }
        }

        public void Release(object instance)
        {
            // ?? not sure what to add here.
            _container.Release(instance);
        }

        // Added for self registering types in each module.
        public IContainer InnerContainer
        {
            get { return _container; }
        }
    }
}